var a = require("../../../@babel/runtime/helpers/toConsumableArray"), t = getApp();

Page({
    data: {
        coupon: "",
        id: "",
        inputs: "",
        order_by: "",
        order_field: "",
        datas: [],
        classifyBol: !0,
        show: !1,
        page: 1
    },
    onLoad: function(a) {
        a.coupon && this.setData({
            coupon: a.coupon
        }), a.id && this.setData({
            id: a.id
        }), a.shop_id && this.setData({
            shop_id: a.shop_id
        }), this.gotoSearch(this.data.page);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.allLoaded ? console.log("没有更多数据") : (this.data.page++, this.gotoSearch(this.data.page));
    },
    onShareAppMessage: function() {},
    sortOut: function(a) {
        var t = a.detail.order_by, o = a.detail.order_field;
        0 != this.data.datas.length && (this.data.page = 1, this.setData({
            datas: [],
            order_field: o,
            order_by: t
        }), this.gotoSearch(this.data.page));
    },
    gotoSearch: function() {
        var o = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1, e = this, s = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.search-goods");
        s += "&search[keyword]=" + this.data.inputs, s += "&page=" + o, s += "&search[category]=" + this.data.id, 
        s += "&order_field=" + this.data.order_field, s += "&order_by=" + this.data.order_by, 
        s += "&search[couponid]=" + this.data.coupon, s += "&shop_id=" + this.data.shop_id, 
        t._getNetWork({
            url: s,
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    if (e.setData({
                        loading: !1,
                        allLoaded: !1
                    }), o.data.data.length <= 0) return void e.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                    if (o.data.current_page > o.data.last_page) return void e.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                    var s = e.data.datas;
                    if (s.push.apply(s, a(o.data.data)), e.setData({
                        datas: s
                    }), o.data.data.length < 20) return void e.setData({
                        loading: !0,
                        allLoaded: !0
                    });
                }
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    classifyBolbtn: function() {
        this.data.show ? this.setData({
            show: !1,
            classifyBol: !0
        }) : this.setData({
            show: !0,
            classifyBol: !1
        });
    },
    inpbtn: function(a) {
        var t = a.detail.value;
        this.setData({
            inputs: t
        });
    },
    search: function() {
        this.data.page = 1, this.setData({
            datas: []
        }), this.gotoSearch(this.data.page, !1);
    }
});